<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>权限管理</title> $!{include("import_js_css.html")}
<link rel="stylesheet" type="text/css"
	href="${viewPath}/resources/css/basic.css" />
</head>
<body>
	$!{include("header.html")}
	<div class="container menu_all">
		<div class="tabbable tabs-left" id="div_ul_tab">
			$!{include("basic_tab.html")}
			<div class="tab-content">
				<!-- 查询条件 -->
				<div class="tab-pane active" id="panel-task">
					<form class="form-horizontal" role="form" name="authorityForm"
						action="yueyogaAdmin/findAllAuthorities.jhtml" method="post">
						<div class="form-group">
							<div class="panel-basic-search">
								<label for="txtUserName" class="col-sm-1 control-label">名称</label>
								<div class="col-sm-3">
									<input type="text" class="form-control" name="name"
										id="txtUserName" value="${name}">
								</div>
								<label for="enabled" class="col-sm-1 control-label">状态</label>
								<div class="col-sm-3">
									<select class="selectpicker" data-width="100%" id="enabled"
										name="enabled">
										<option value="1">启用</option>
										<option value="2">禁用</option>
									</select>
								</div>
								<br /> <br /> <input type="hidden" name="pageNo"
									id="hidPageNo" />
								<div class="panel-btn-basic">
									<button type="submit" class="btn-ade-default2">搜索</button>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
			<!-- 查询结果 -->
			<div class="div_search_result">
				<div class="panel-heading panel-result-title">
					<h3 class="panel-title">查询结果</h3>
					<div class="btn-group btn-group-sm btn-gp-default">
						<button id="btn_add" type="button"
							class="btn btn-default panel-radius-left">添加</button>
						<button id="btn_delete" type="button"
							class="btn btn-default panel-radius-none">删除</button>
						<button id="btn_resource" type="button"
							class="btn btn-default panel-radius-right">指定资源</button>
					</div>
				</div>

				<table class="table table-bordered table-hover table-condensed tb"
					style="text-align: center; border-bottom: 1px solid #DDDDDD;">
					<tr>
						<td width="100"><input id="chkallIds" type="checkbox" /></td>
						<td width="100">编号</td>
						<td width="290">名称</td>
						<td width="290">资源</td>
						<td width="290">描述</td>
						<td width="100">状态</td>
					<tr>
						<!--#set(PaginatedList<Authority> authorities)  -->
						<!--#for(Authority authority : authorities)-->
					<tr>
						<td><input name="chk_name" type="checkbox"
							value="${authority.id}" /></td>
						<td>${authority.id}</td>
						<td>${authority.name}</td>
						<td>${authority.zymc}</td>
						<td>${authority.description}</td>
						<td>${authority.enabled==true?'启用':'禁用'}</td>
					</tr>
					<!--#end-->
				</table>
				<div class="div_page main_div_page">
					<!--
					#set(
						pager = authorities.pager,
						totalResults = pager.getCountOfTotalResults(),
						totalPages = pager.getCountOfTotalPages() * 1,
						pageSize = pager.pageSize,
						pageNo = pager.pageNo,
						prePageNo = pager.getPrevPageNo(),
						nextPageNo = pager.getNextPageNo()
					)
				-->
					<!-- 列表分页 -->
					<div class="paging-page">$!{include("paging_page.html")}</div>
					<div id="asd_resource" class="panel-dialog-box panel-radius-all"
						style="width: 420px; display: none; z-index: 1000; min-height: 180px;">
						<div class="panel-heading panel-result-title">
							<h3 class="panel-title">指定资源</h3>
							<br><br> 
							<label class="col-sm-1 control-label">当前资源</label>
							<label id="lbcurResources" style="width: 275px !important;" class="col-sm-1 control-label"></label> 
							<br> <br> 
							<label for="selResoures" class="col-sm-1 control-label">重定资源</label>
							<div class="col-sm-8">
								<select class="selectpicker" multiple data-width="100%" name="resources" id="selResoures">
									<option value=""></option>
									<!-- #for(Resource res:resources) -->
									<option value="${res.id},">${res.name}</option>
									<!-- #end -->
								</select>
							</div>
							<br> <br> 
							
							<input type="hidden" id="hidAuthorityId" />
							<div class="panel-btn-search" style="float: left; text-align: right; margin-top: 20px; margin-left: 110px;">
								<button id="btnGrantResource" type="button"	class="btn-adet-default">保存</button>
								&nbsp;&nbsp;&nbsp;
								<button type="button" id="btn_close" onclick="slideToggleDIV()"	class="btn-adet-default">取消</button>
							</div>
							
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$(function() {
		
		$("#enabled").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
		
		var enabled = '${enabled}';
		$("#enabled").select2("val", enabled);
		$("#chkallIds").click(function() {
			$(this).prop("checked", $(this).prop("checked"));
			$("input[name=chk_name]").prop("checked", $(this).prop("checked"));
		});
		$("#btn_add").click(function() {
			window.location.href = "yueyogaAdmin/toAddAuthority.jhtml";
		});
		$("#btn_delete").click(
				function() {
					var arr = new Array();
					$("input[name=chk_name]:checked").each(function() {
						arr.push($(this).val());
					});
					if (arr.length > 0) {
						confirm('确定要删除吗？', function() {
							var url = "yueyogaAdmin/deleteAuthority.jhtml?ids="
									+ arr;
							$.post(url, function(resp) {
								var data = eval('(' + resp + ')');
								if (data.success) {
									var d = alert(data.msg);
									setTimeout(function() {
										d.close().remove();
										$("input[name=chk_name]").prop(
												"checked", false);
									}, 1000);
									$("form[name=authorityForm]").submit();
								} else {
									error(data.msg);
								}
							});
						});
					} else {
						alert("请选择您要删除的记录!");
					}
				});
		$("#btn_resource")
				.click(
						function() {
							var arr = new Array();
							$("input[name=chk_name]:checked").each(function() {
								arr.push($(this).val());
							});
							if (arr.length == 1) {
								$("#selResoures").select2("val", "");
								$("#asd_resource").show();
								var url = "yueyogaAdmin/findAuthorityResources.jhtml?auId="
										+ arr;
								$("#hidAuthorityId").val(arr);
								$.post(url, function(resp) {
									var data = eval('(' + resp + ')');
									var str = '';
									var msg = eval('(' + data.msg + ')');
									if (data.success) {
										$.each(msg, function(i, val) {
											str = str + val.name + ',';
										});
										str = str.substring(0, str.length - 1);
										$("#lbcurResources").text(str);
									}
								});
							} else {
								var s = alert("请选择一条记录进行操作!");
								setTimeout(function() {
									s.close().remove();
								}, 1000);
							}
						});

		$("#btnGrantResource")
				.click(
						function() {
							var rsId = $("#selResoures").select2("val") + "";
							var auId = $("#hidAuthorityId").val();
							if (rsId && rsId.length > 0) {
								rsId = rsId.substring(0, rsId.length - 1);
								var url = "yueyogaAdmin/grantAuthorityResources.jhtml?rsId="
										+ rsId + "&auId=" + auId;
								$.post(url, function(resp) {
									slideToggleDIV();
									var data = eval('(' + resp + ')');
									if (data.success) {
										 var d = alert(data.msg);
										setTimeout(function() {
											d.close().remove();
											$("input[name=chk_name]").prop(
													"checked", false);
											$("#selResoures").select2("val", "");
										}, 1000);
										window.location.href="yueyogaAdmin/findAllAuthorities.jhtml";
									} else {
										error(data.msg);
									}
								});
							} else {
								slideToggleDIV();
								var d = alert("请选择资源!");
								setTimeout(function() {
									d.close().remove();
								}, 1000);
							}

						});
	});
	function slideToggleDIV() {
		$("#asd_resource").slideToggle(0);
	}

	function changePage(value) {
		value = value * 1;
		var totalPages = '${totalPages}';
		if (value > totalPages) {
			value = totalPages;
		} else if (value < 1) {
			value = 1;
		}
		$("#txtPageNumber").val(value);
		goToPage(value);
	}
	function goToPage(pageNo) {
		$("#hidPageNo").val(pageNo);
		document.authorityForm.submit();
	}
</script>
</html>